home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TextensionCommon.h
-
- Contains: xxx put contents here xxx
-
- Written by: Essam Zaky
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 1/4/94 EZ clean up
- <1> 1/4/94 EZ first checked in
-
- */
-
-
- #ifndef _TextensionCommon_
- #define _TextensionCommon_
-
- #ifndef _ToolBoxDump_
- #include "ToolBoxDump.h"
- #endif
-
- #ifdef sysTextPerf
- #include <Timer.h>
- #endif
- //***************************************************************************************************
-
- #if !defined(applec) || defined(__SC__)
- class SingleObject {
- };
- #endif
-
- #ifdef __STDC__
- class HandleObject {
- };
- #if defined(applec) || defined(__SC__)
- #error "•••handle object redefined"
- #endif
- #endif
- //****************************************************
-
-
- typedef long* longPtr;
- typedef Fixed* FixedPtr;
- typedef short* shortPtr;
- typedef RGBColor* RGBColorPtr;
- typedef unsigned char uchar;
- typedef uchar* uPtr;
- typedef unsigned short ushort;
- typedef unsigned long ulong;
- //***************************************************************************************************
-
-
- const short kMaxInt = 0x7FFF;
- const long kMaxLongInt = 0x7FFFFFFF;
-
- //Direction constants
- const char kRL = -1;
- const char kLR = 0;
- const char kSysDirection = 1;
- const char kLineDirection = 2; //returned only from non text styles
- //****************************************************
-
- //Direction CaretDirection
- const char kRLCaret = -1;
- const char kLRCaret = 0;
- const char kRunDir = 1;
- //****************************************************
-
- //const for sel state and objects hilite
- const char kSelOff = 0;
- const char kSelOn = 1;
- const char kSelInactiv = 2;
- //****************************************************
-
- //special characters
-
- const uchar kMaxCtrlChar = 0x1F; //•• used in TextensionUtil.a (GetCtrlCharOffset)
-
- const uchar kRLArrowCharCode = 0x1C;
- const uchar kLRArrowCharCode = 0x1D;
- const uchar kUpArrowCharCode = 0x1E;
- const uchar kDownArrowCharCode = 0x1F;
-
- const uchar kTabCharCode = 9;
- const uchar kCRCharCode = 0xD;
- const uchar kRomanSpaceCharCode = 0x20;
-
- const uchar kClearCharCode = 0x1B;
- const uchar kBackSpaceCharCode = 8;
-
- //****************************************************
-
- typedef short TSize;
- //const for "sizeInfo" param to ITextension
- const TSize kSmallSize = 0;
- const TSize kMediumSize = 1;
- const TSize kLargeSize = 2;
- //****************************************************
-
- struct TOffsetPair {
- long firstOffset;
- long lastOffset;
- };
- //****************************************************
-
- //For run boundaries select problem(including script problems) ••• to be more documented
- /*trailEdge is to distinguish between for instance offset 5 as either the end of the fifth char or the start
- of the 6th char (this may be different in display if text is mixed LR and RL)
- */
- struct TOffset {
- long offset;
- Boolean trailEdge;
-
- TOffset() {}
-
- TOffset(long theOffset, Boolean trail = false) {
- offset = theOffset;
- trailEdge = trail;
- }
-
- inline operator long() {return offset;}
-
- void Set(long theOffset, Boolean trail = false) {
- offset = theOffset;
- trailEdge = trail;
- }
-
- Boolean operator==(const TOffset& other) const;
- inline Boolean operator!=(const TOffset& other) const
- {return !(*this == other);}
- };
- //****************************************************
-
- struct TOffsetRange {
- TOffset rangeStart;
- TOffset rangeEnd;
-
- TOffsetRange() {}
-
- TOffsetRange(const TOffset& start, const TOffset& end);
-
- TOffsetRange(long offsetStart, long offsetEnd, Boolean trailStart = false, Boolean trailEnd = true);
-
- void Set(long offsetStart, long offsetEnd, Boolean trailStart, Boolean trailEnd);
-
- inline long Len() const {return rangeEnd.offset-rangeStart.offset;}
-
- long Start() const {return rangeStart.offset;}
- long End() const {return rangeEnd.offset;}
- Boolean IsEmpty() const {return rangeStart.offset == rangeEnd.offset;}
-
- Boolean operator==(const TOffsetRange& other) const;
- inline Boolean operator!=(const TOffsetRange& other) const
- {return !(*this == other);}
-
- void Offset(long value);
-
- void CheckBounds(); //swap range start, rangeEnd if necessary
- };
- //****************************************************
-
-
- struct TLineHiteInfo {
- short lineHite;
- short lineAscent;
- };
- //***************************************************************************************************
-
- struct TTempReference {
- void* reference;
- char used;
- };
-
- const kMaxTempReferences = 5;
-
- class CTempReferences : private SingleObject {
- public:
- CTempReferences() {}
-
- void ITempReferences();
- void Free();
-
- void* Get();
- void Done(void* theRef);
-
- #ifdef txtnDebug
- short Count();
- void Clean();
- #endif
-
- protected:
- virtual void* CreateNewReference() = 0;
- virtual void FreeReference(void* ref) = 0;
-
- private:
- TTempReference fReferences[kMaxTempReferences];
- };
- //***************************************************************************************************
-
- class CTempRegions : public CTempReferences {
- public:
- CTempRegions() {}
-
- inline void ITempRegions() {this->ITempReferences();}
-
- inline RgnHandle GetRegion() {return RgnHandle(this->Get());}
- inline void DoneWithRegion(RgnHandle theRgn) {this->Done(theRgn);}
-
- protected:
- virtual void* CreateNewReference();
- virtual void FreeReference(void* ref);
-
- private:
- };
- //***************************************************************************************************
-
- #ifdef sysTextPerf
- const short kPerfFormatCall = 0;
- const short kPerfPixel2CharCall = 1;
- const short kPerfChar2PixelCall = 2;
- const short kPerfDrawCall = 3;
-
- const short kCountPerfCalls = 4;
-
- class CSysTextPerformance : private SingleObject {
- public :
- CSysTextPerformance() {fCount = 0;}
-
- void StartCount();
- void EndCount();
-
- inline char IsOn() {return fCount;}
-
- void PreCall(short callId);
- void PostCall(short callId);
-
- inline long GetCounterValue(short callId) {return fCounters[callId];}
-
- private:
- long fCounters[kCountPerfCalls];
- char fCount;
- TMTask fTimerTask;
- short fSavedSR;
- long fOverhead;
- };
- //***************************************************************************************************
- #endif
-
- //••• Globals
- extern char gHasManyScripts;
- extern Boolean gSys2Directions;
- extern Boolean g2Bytes;
-
- #ifndef txtnSys7
- extern Boolean gSystem7OrNewer;
-
- extern Boolean gUseScriptManager7; //testing purposes, allow to test old script manager routines
- #endif
-
- extern Boolean gHasColor;
-
- extern Boolean gTextensionImaging;
-
- /*••this is declared as reference instead of as an automatic "CTempRegions gTempRegions;" since
- the power pc compiler has a problem in the later case (the virtual table of gTempRegions is not initialized
- . Actually, it's better to create it in the heap to reduce the global area */
- extern CTempRegions* gTempRegions;
-
-
- #ifdef sysTextPerf
- extern CSysTextPerformance gSysTextPerf;
- #endif
- //***************************************************************************************************
-
- struct TxtnLongRect; //later
- //***************************************************************************************************
-
- Handle AllocateTempHandle(Size countBytes, char lockIt, OSErr* err);
-
- long GetSysScrapTypeSize(ResType theType);
-
- inline long MaxLong(long long1, long long2) {return((long1 > long2) ? long1 : long2);}
- inline long MinLong(long long1, long long2) {return((long1 < long2) ? long1 : long2);}
-
- long Clip(long val, long lowerBound, long upperBound);
- inline short ClipToInt(long val) {return short(Clip(val, -kMaxInt, kMaxInt));}
-
- void SwapShort(short* short1, short* short2);
- void SwapLong(long* long1, long* long2);
-
- inline short RectHite(const Rect theRect) {return (theRect.bottom - theRect.top);}
- inline short RectWidth(const Rect theRect) {return (theRect.right - theRect.left);}
-
- Boolean IsColorPort();
-
- short GetMaxPixDepth(const Rect& aRect);
-
- void SetCursorIBeam();
-
- /* •••
- This routine is here since since for instance in AIS : Font2Script returns 4 when font is roman and
- forceFont flag is on, the same problem should exist in other systems
- */
- short MonoFont2Script(short aFont);
- Boolean IsScript2Bytes(short theScript);
- inline Boolean IsScriptR2L(short theScript) {return GetScript(theScript, smScriptRight) != 0;}
-
- inline short Script2DefaultFont(short scriptNo)
- {return short(GetScript(scriptNo, smScriptAppFond));}
-
- void MyKeyScript(short newScript);
-
- Boolean DoScrollRect(const Rect* rect2Scroll, long hPix, long vPix, RgnHandle invalidRgn
- , Boolean move = false);
-
- long LongRoundUp(long aNumber, short aModulus);
- short ShortRoundUp(short aNumber, short aModulus);
-
- #ifdef txtnScal
- short ScaleVal(short val2Scale, short numer, short denom, Boolean roundUp = true);
- long LongScaleVal(long val2Scale, short numer, short denom, Boolean roundUp = true);
- #endif
-
- Fixed FixScaleVal(Fixed val2Scale, short numer, short denom);
-
- #ifndef txtnRulers
- #ifdef txtnScal
- Fixed GetDefaultTabWidth(Fixed tabPixStart, short numer = 1, short denom = 1);
- #else
- Fixed GetDefaultTabWidth(Fixed tabPixStart);
- #endif
- #endif
-
- inline Boolean IsCtrlChar(uchar theChar) {return theChar <= kMaxCtrlChar;}
-
-
-
- //***************************************************************************************************
-
- //•externals
-
- extern pascal short GetCtrlCharOffset(uPtr chars, short len, unsigned char* theChar); //returns the offset of the char, -1 if not found
- extern pascal short SearchChar(uchar theChar, uPtr chars, short len); //returns the offset of the char from "chars", -1 if not found
- extern pascal short SearchCharBack(uchar theChar, uPtr chars, short lenBefore); //same as SearchChar but search backward
-
- extern pascal void Add2ArrayElements(long value, char* startPtr, long count, short elemSize);
-
- #ifndef powerc
- extern pascal void Add2LongArray(long value, char* startPtr, long count);
- #endif
-
- extern "C" {
- extern char CompareBytes(uPtr ptr1, uPtr ptr2, long count);
- //••only the short part is used from "count". declared as long since the compiler pushes 4 bytes when "extern C"
- }
-
- //***************************************************************************************************
-
- struct LongPoint {
- //the order of v and h is the same as the toolbox and VPoint in MacApp, don't change
- long v;
- long h;
-
- //••LongPoint members should not move memory, they can be members of Handle objects
- LongPoint() {}
-
- LongPoint(long horiz, long ver) {
- h = horiz;
- v = ver;
- }
-
- LongPoint(Point shortPt) {
- h = shortPt.h;
- v = shortPt.v;
- }
-
- inline void Set(long horiz, long ver) {
- h = horiz;
- v = ver;
- }
-
- inline Boolean operator==(const LongPoint& aPoint) const {return (h == aPoint.h) && (v == aPoint.v);}
- inline Boolean operator!=(const LongPoint& aPoint) const {return (h != aPoint.h) || (v != aPoint.v);}
- };
- //***************************************************************************************************
-
-
- struct TxtnLongRect {
- //the order top, left, bottom, right is the same as the toolbox and VRect in MacApp, don't change
- long top;
- long left;
- long bottom;
- long right;
-
- //••TxtnLongRect members should not move memory, they can be members of Handle objects
-
- inline TxtnLongRect(long l, long t, long r, long b) {
- left = l;
- top = t;
- right = r;
- bottom = b;
- }
-
- inline TxtnLongRect() {}
-
- inline TxtnLongRect(Rect shortRect) { //implicit conversion from Rect to TxtnLongRect
- left = shortRect.left;
- top = shortRect.top;
- right = shortRect.right;
- bottom = shortRect.bottom;
- }
-
- inline void Set(long l, long t, long r, long b) {
- left = l;
- top = t;
- right = r;
- bottom = b;
- }
-
- inline long Hite() const {return bottom-top;}
- inline long Width() const {return right-left;}
-
- Boolean Sect(const TxtnLongRect* src, TxtnLongRect* intersection) const;
-
- Boolean IsPointInside(const LongPoint* thePt) const;
-
- void Inset(long h, long v);
-
- void Offset(long h, long v);
-
- Boolean operator==(const TxtnLongRect& aRect) const;
- inline Boolean operator!=(const TxtnLongRect& aRect) const
- {return !(*this == aRect);}
- };
- //***************************************************************************************************
-
-
- inline Boolean IsRectRgn(RgnHandle aRgn) {return (*aRgn)->rgnSize == 10;}
-
- Boolean ClipFurther(Rect* moreClipRect, RgnHandle origClip);
- Boolean CalcClipRect(Rect* theRect);
-
- void InvalSectRect(Rect* theRect, RgnHandle theClip = nil);
-
- //***************************************************************************************************
-
-
- #ifdef txtnDebug
- #define TX_DebugMessage(message) DebugStr(message)
- #else
- #define TX_DebugMessage(message)
- #endif
- //***************************************************************************************************
-
- #endif
-